package algorithm;

/**
 * @description: 杨辉三角形
 * @author: apple
 * @date:  2021/11/16 4:43 下午
 * @version 1.0
 **/
public class YangHui {

    public static void main(String[] args) {
        int[][] nums = new int[10][];
        for (int i = 0; i < 10; i++) {
            nums[i] = new int[i+1];
            // 首末元素赋值为1
            nums[i][0] = nums[i][i] = 1;
            if (i > 1) {
                for (int j = 1; j < nums[i].length - 1 ; j++) {
                    nums[i][j] = nums[i-1][j-1] + nums[i-1][j];
                }
            }
        }
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums[i].length; j++) {
                System.out.print(nums[i][j] + " ");
            }
            System.out.println();
        }

    }
}
